//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <core.h>

#ifdef _x86
EXTERN_C ECode CDECL SysReboot();
#elif defined _techfaith
EXTERN_C void CDECL TechReboot();
#endif

void* g_pRebootEvent = NULL;

Int32 AutoReboot(void* arg)
{
    DzEvent* pcEvent = new DzEvent(TRUE, 1);
    g_pRebootEvent = pcEvent;
    WaitResult wr;
    pcEvent->Clear();
    kprintf("before wait\n");
    pcEvent->Wait(&wr, NULL);
    kprintf("after wait\n");
    delete pcEvent;
#ifdef _x86
    SysReboot();
#elif defined _techfaith
    TechReboot();
#elif defined _gingko
    BspReboot();
#endif

    return NOERROR;
}

EXTERN_C DECL_CODEINIT void CDECL TestInitMantle()
{
    kprintf("TestInitMantle\n");
}

EXTERN_C void CDECL TestMantleEntry()
{
    kprintf("TestMantleEntry\n");
    ECode ec = DzCreateKernelThread(                                \
                AutoReboot, NULL, CreateThreadFlag_System,          \
                ThreadPriorityRank_Normal, NULL);

    kprintf("CreateKernelThread ec = %x\n", ec);
}
